<template>
	<view class="container">
		<view class="header">
			<text class="title">完整测试页面</text>
		</view>
		
		<!-- 用户信息卡片 -->
		<view class="info-card">
			<view class="card-header">
				<text class="card-title">用户信息</text>
			</view>
			<view class="info-content">
				<view class="info-row">
					<text class="info-label">用户名:</text>
					<text class="info-value">{{ userInfo.username || '未登录' }}</text>
				</view>
				<view class="info-row">
					<text class="info-label">昵称:</text>
					<text class="info-value">{{ userInfo.name || '无' }}</text>
				</view>
				<view class="info-row">
					<text class="info-label">角色:</text>
					<text class="info-value">{{ userInfo.roles ? userInfo.roles.join(', ') : '无' }}</text>
				</view>
				<view class="info-row">
					<text class="info-label">权限:</text>
					<text class="info-value">{{ userInfo.permissions ? userInfo.permissions.length + '个' : '无' }}</text>
				</view>
			</view>
		</view>
		
		<!-- 权限管理器状态 -->
		<view class="info-card">
			<view class="card-header">
				<text class="card-title">权限管理器状态</text>
			</view>
			<view class="info-content">
				<view class="info-row">
					<text class="info-label">角色键:</text>
					<text class="info-value">{{ roleKey }}</text>
				</view>
				<view class="info-row">
					<text class="info-label">角色配置:</text>
					<text class="info-value">{{ roleConfig ? roleConfig.name : '无' }}</text>
				</view>
				<view class="info-row">
					<text class="info-label">主题:</text>
					<text class="info-value">{{ roleConfig ? roleConfig.theme : '无' }}</text>
				</view>
				<view class="info-row">
					<text class="info-label">菜单项数量:</text>
					<text class="info-value">{{ menuItems.length }} 个</text>
				</view>
			</view>
		</view>
		
		<!-- 菜单项列表 -->
		<view class="info-card" v-if="menuItems.length > 0">
			<view class="card-header">
				<text class="card-title">菜单项列表</text>
			</view>
			<view class="menu-list">
				<view class="menu-item" v-for="item in menuItems" :key="item.key">
					<view class="menu-icon">{{ item.icon }}</view>
					<view class="menu-info">
						<text class="menu-name">{{ item.name }}</text>
						<text class="menu-path">{{ item.path }}</text>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 权限检查 -->
		<view class="info-card">
			<view class="card-header">
				<text class="card-title">权限检查</text>
			</view>
			<view class="permission-list">
				<view class="permission-item">
					<text class="permission-label">是管理员:</text>
					<text class="permission-value" :class="isAdmin ? 'success' : 'fail'">{{ isAdmin ? '是' : '否' }}</text>
				</view>
				<view class="permission-item">
					<text class="permission-label">是维修人员:</text>
					<text class="permission-value" :class="isMaintenanceWorker ? 'success' : 'fail'">{{ isMaintenanceWorker ? '是' : '否' }}</text>
				</view>
				<view class="permission-item">
					<text class="permission-label">是仓库管理员:</text>
					<text class="permission-value" :class="isWarehouseManager ? 'success' : 'fail'">{{ isWarehouseManager ? '是' : '否' }}</text>
				</view>
			</view>
		</view>
		
		<!-- 操作按钮 -->
		<view class="actions">
			<button class="action-btn primary" @click="loadData">重新加载</button>
			<button class="action-btn secondary" @click="goBack">返回</button>
		</view>
	</view>
</template>

<script>
	import permissionManager from '@/utils/permission.js'
	
	export default {
		data() {
			return {
				userInfo: {},
				roleKey: '',
				roleConfig: null,
				menuItems: [],
				isAdmin: false,
				isMaintenanceWorker: false,
				isWarehouseManager: false
			}
		},
		onLoad() {
			this.loadData();
		},
		methods: {
			loadData() {
				console.log('开始加载完整测试数据...');
				
				// 加载用户信息
				const { getUserInfo } = require('@/utils/auth');
				this.userInfo = getUserInfo() || {};
				console.log('用户信息:', this.userInfo);
				
				// 设置权限管理器
				if (this.userInfo && Object.keys(this.userInfo).length > 0) {
					permissionManager.setUserInfo(this.userInfo);
					console.log('权限管理器已设置用户信息');
				}
				
				// 获取权限管理器状态
				this.roleKey = permissionManager.getRoleKey();
				this.roleConfig = permissionManager.getRoleConfig();
				this.menuItems = permissionManager.getMenuItems();
				
				// 权限检查
				this.isAdmin = permissionManager.isAdmin();
				this.isMaintenanceWorker = permissionManager.isMaintenanceWorker();
				this.isWarehouseManager = permissionManager.isWarehouseManager();
				
				console.log('完整测试数据:', {
					userInfo: this.userInfo,
					roleKey: this.roleKey,
					roleConfig: this.roleConfig,
					menuItems: this.menuItems,
					permissions: {
						isAdmin: this.isAdmin,
						isMaintenanceWorker: this.isMaintenanceWorker,
						isWarehouseManager: this.isWarehouseManager
					}
				});
				
				uni.showToast({
					title: '数据加载完成',
					icon: 'success'
				});
			},
			
			goBack() {
				uni.navigateBack();
			}
		}
	}
</script>

<style scoped>
	.container {
		padding: 20rpx;
		background-color: #f5f5f5;
		min-height: 100vh;
	}
	
	.header {
		text-align: center;
		margin-bottom: 40rpx;
	}
	
	.title {
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
	}
	
	.info-card {
		background: white;
		border-radius: 16rpx;
		margin-bottom: 20rpx;
		overflow: hidden;
		box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
	}
	
	.card-header {
		background-color: #f8f9fa;
		padding: 20rpx 30rpx;
		border-bottom: 1rpx solid #e9ecef;
	}
	
	.card-title {
		font-size: 28rpx;
		font-weight: bold;
		color: #333;
	}
	
	.info-content {
		padding: 30rpx;
	}
	
	.info-row {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 16rpx;
		padding: 12rpx 0;
		border-bottom: 1rpx solid #f0f0f0;
	}
	
	.info-row:last-child {
		border-bottom: none;
		margin-bottom: 0;
	}
	
	.info-label {
		font-size: 26rpx;
		color: #666;
		font-weight: 500;
	}
	
	.info-value {
		font-size: 26rpx;
		color: #333;
		font-weight: bold;
	}
	
	.menu-list {
		padding: 30rpx;
	}
	
	.menu-item {
		display: flex;
		align-items: center;
		padding: 20rpx;
		margin-bottom: 12rpx;
		background-color: #f8f9fa;
		border-radius: 12rpx;
		border: 1rpx solid #e9ecef;
	}
	
	.menu-item:last-child {
		margin-bottom: 0;
	}
	
	.menu-icon {
		font-size: 40rpx;
		margin-right: 20rpx;
		width: 60rpx;
		text-align: center;
	}
	
	.menu-info {
		flex: 1;
	}
	
	.menu-name {
		display: block;
		font-size: 28rpx;
		color: #333;
		font-weight: bold;
		margin-bottom: 4rpx;
	}
	
	.menu-path {
		font-size: 22rpx;
		color: #666;
	}
	
	.permission-list {
		padding: 30rpx;
	}
	
	.permission-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 16rpx 0;
		border-bottom: 1rpx solid #f0f0f0;
	}
	
	.permission-item:last-child {
		border-bottom: none;
	}
	
	.permission-label {
		font-size: 26rpx;
		color: #666;
	}
	
	.permission-value {
		font-size: 26rpx;
		font-weight: bold;
		padding: 8rpx 16rpx;
		border-radius: 8rpx;
	}
	
	.permission-value.success {
		background-color: #d4edda;
		color: #155724;
	}
	
	.permission-value.fail {
		background-color: #f8d7da;
		color: #721c24;
	}
	
	.actions {
		display: flex;
		gap: 20rpx;
		margin-top: 40rpx;
	}
	
	.action-btn {
		flex: 1;
		height: 80rpx;
		border: none;
		border-radius: 8rpx;
		font-size: 28rpx;
		font-weight: bold;
	}
	
	.action-btn.primary {
		background-color: #409EFF;
		color: white;
	}
	
	.action-btn.secondary {
		background-color: #909399;
		color: white;
	}
</style>
